home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
xlisp.lbr
/
XLIO.CQ
/
xlio.c
Wrap
Text File
|
1985-06-03
|
3KB
|
130 lines
/* xlio - xlisp i/o routines */
#ifdef CI_86
#include "a:stdio.h"
#include "xlisp.h"
#endif
#ifdef AZTEC
#include "a:stdio.h"
#include "xlisp.h"
#endif
#ifdef unix
#include <stdio.h>
#include <xlisp.h>
#endif
/* global variables */
int (*xlgetc)();
int xlpvals;
int xlplevel;
/* local variables */
static int prompt;
static FILE *ifp;
/**********************************************
* tgetc - get a character from the terminal *
**********************************************/
static int tgetc()
{
int ch;
if (prompt) /* Prompt if required */
{
if (xlplevel > 0)
printf("%d> ", xlplevel);
else
printf("> ");
prompt = FALSE;
}
if ((ch = getc(stdin)) == '\n')
prompt = TRUE;
return (ch);
}
/*********************************
* xltin - setup terminal input *
*********************************/
int xltin(flag)
int flag;
{
if (flag & !prompt) /* Flush line if flag set */
while (tgetc() != '\n')
;
prompt = TRUE;
xlplevel = 0;
xlgetc = tgetc;
xlpvals = TRUE;
}
/*****************************************
* fgetcx - get a character from a file *
*****************************************/
static int fgetcx()
{
int ch;
if ((ch = getc(ifp)) <= 0) {
xlgetc = tgetc;
xlpvals = TRUE;
return (tgetc());
}
return (ch);
}
/*****************************
* xlfin - setup file input *
*****************************/
xlfin(str)
char *str;
{
#ifdef DEFEXT
char fname[100];
strcpy(fname, str);
#else
#define fname str
#endif
if ((ifp = fopen(fname, "r")) != NULL)
{
xlgetc = fgetcx;
xlpvals = FALSE;
return;
}
#ifdef DEFEXT
if (strchr(fname, '.') == 0)
strcat(fname, ".lsp");
if ((ifp = fopen(fname, "r")) != NULL)
{
xlgetc = fgetcx;
xlpvals = FALSE;
return;
}
#endif
printf("Can't open \"%s\" for input\n", fname);
}